package com.cupcorn.lib.display;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Handler;
import android.widget.EditText;

import com.cupcorn.lib.game.element.GameElementDialog;

public class DisplayDialog
{
	public AlertDialog[]	alertDialog;
	public EditText			editText;
	public Context			theEngine;
	public String			answer;
	public int				id;
	public boolean			positiveJustClicked, negativeJustClicked, showed;
	public boolean			usePositive, useNegative, useEditText;
	
	Handler					handler	= new Handler();
	
	public DisplayDialog(Context mainActivity, GameElementDialog[] gameElementDialog, int id)
	{
		this.id = id;
		theEngine = mainActivity;
		
		alertDialog = new AlertDialog[gameElementDialog.length];
		
		for (int i = 0; i < gameElementDialog.length; i++)
		{
			final GameElementDialog _gameElementDialog = gameElementDialog[i];
			
			Builder builder = new AlertDialog.Builder(theEngine).setTitle(_gameElementDialog.title).setCancelable(_gameElementDialog.cancelable);
			
			if (_gameElementDialog.useEditText)
			{
				editText = new EditText(theEngine);
				builder.setView(editText);
			}
			
			if (_gameElementDialog.useNegativeButton) builder.setNegativeButton(_gameElementDialog.negativeButton, new OnClickListener()
			{
				@Override
				public void onClick(DialogInterface arg0, int arg1)
				{
					negativeJustClicked = true;
				}
			});
			
			if (_gameElementDialog.usePositiveButton) builder.setPositiveButton(_gameElementDialog.positiveButton, new OnClickListener()
			{
				@Override
				public void onClick(DialogInterface arg0, int arg1)
				{
					if (_gameElementDialog.useEditText) answer = editText.getText().toString();
					positiveJustClicked = true;
				}
			});
			alertDialog[i] = builder.create();
		}
		
	}
	
	// public void AddDialog(int id, int index)
	// {
	// final int _id = id;
	// final int _index = index;
	// handler.postDelayed(new Runnable()
	// {
	//
	// @Override
	// public void run()
	// {
	// gameDialog[_index] = new ADialog(GameEngine.this, _index, _id);
	// }
	// }, 1);
	// }
	//
	// public void ShowDialog(int id)
	// {
	// final int _id = id;
	// alertDialog[id].showed = true;
	// handler.postDelayed(new Runnable()
	// {
	//
	// @Override
	// public void run()
	// {
	// DisplayDialog.this.showDialog(_id);
	// }
	// }, 1);
	// }
}
